<template>
  <!-- 造型计划填报表单弹窗 -->
  <el-dialog
    v-model="visibleDialog"
    :title="props.title"
    width="70%"
    draggable
    @close="closeDialog"
    :append-to-body="true"
  >
    <el-descriptions
      class="margin-top"
      title=""
      :column="2"
      size="large"
      v-show="props.isReadonly"
      border
    >
      <!--<el-descriptions-item>
        <template #label>
          <div class="cell-item">砂处理供砂量</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandDisposeSupply }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">型砂使用量</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.mouldingSandUsageAmount }}
        </div>
      </el-descriptions-item>-->
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">浇注模数</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.pouringMouldQuantity }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">实际造型模数</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.actualModelMouldQuantity }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">实际浇注模数</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.actualPouringMouldQuantity }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">造型废型</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.modelAbandon }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">浇注废型</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.pouringAbandon }}
        </div>
      </el-descriptions-item>
      <!--<el-descriptions-item>
        <template #label>
          <div class="cell-item">实际重量</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.actualWeight }}
        </div>
      </el-descriptions-item>-->
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">实际件数</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.actualQuantity }}
        </div>
      </el-descriptions-item>
      <!--<el-descriptions-item>
        <template #label>
          <div class="cell-item">实际铁水重量</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.actualWaterWeight }}
        </div>
      </el-descriptions-item>-->
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">实际包待（分钟）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.actualPackage }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">实际炉待（分钟）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.actualStove }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">炉号</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.stoveNum }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">模板框号</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.templateNum }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">压力（上）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.pressureOn }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">压力（下）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.pressureDown }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">加砂量（上）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandQuantityUp }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">加砂量（下）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandQuantityDown }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">砂模硬度1（上）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandMould1Up }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">砂模硬度1（下）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandMould1Down }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">砂模硬度2（上）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandMould2Up }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">砂模硬度2（下）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandMould2Down }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">砂模硬度3（上）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandMould3Up }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">砂模硬度3（下）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandMould3Down }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">砂模硬度4（上）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandMould4Up }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">砂模硬度4（下）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandMould4Down }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">砂模硬度5（上）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandMould5Up }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">砂模硬度5（下）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandMould5Down }}
        </div>
      </el-descriptions-item>
      <!--<el-descriptions-item>
        <template #label>
          <div class="cell-item">砂模硬度6（上）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandMould6Up }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">砂模硬度6（下）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandMould6Down }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">砂模硬度7（上）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandMould7Up }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">砂模硬度7（下）</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandMould7Down }}
        </div>
      </el-descriptions-item>-->
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">下芯人员</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.coreSettingUserName }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">砂芯批号</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandCoreBatch }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">砂芯数量</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.sandCoreQuantity }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">过滤片数量</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.filterQuantity }}
        </div>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">过滤片批号</div>
        </template>
        <div style="width: 50%; word-break: break-all">
          {{ formData.filterBatch }}
        </div>
      </el-descriptions-item>
    </el-descriptions>
    <el-form
      ref="formRef"
      :model="formData"
      :rules="rules"
      label-width="160"
      v-show="!props.isReadonly"
    >
      <el-row>
        <!--<el-col :span="6">
          <el-form-item
            label="砂处理供砂量"
            prop="sandDisposeSupply"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandDisposeSupply"
              placeholder="请输入砂处理供砂量"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="型砂使用量"
            prop="mouldingSandUsageAmount"
            label-width="110px"
          >
            <el-input
              v-model="formData.mouldingSandUsageAmount"
              placeholder="请输入型砂使用量"
              clearable
            />
          </el-form-item>
        </el-col>-->
        <el-col :span="6">
          <el-form-item
            label="浇注模数"
            prop="pouringMouldQuantity"
            label-width="110px"
          >
            <el-input
              v-model="formData.pouringMouldQuantity"
              placeholder="请输入浇注模数"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="实际造型模数"
            prop="actualModelMouldQuantity"
            label-width="110px"
          >
            <el-input
              v-model="formData.actualModelMouldQuantity"
              placeholder="请输入实际造型模数"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="实际浇注模数"
            prop="actualPouringMouldQuantity"
            label-width="110px"
          >
            <el-input
              v-model="formData.actualPouringMouldQuantity"
              placeholder="请输入实际浇注模数"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="造型废型" prop="modelAbandon" label-width="110px">
            <el-input
              v-model="formData.modelAbandon"
              placeholder="请输入造型废型"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="浇注废型"
            prop="pouringAbandon"
            label-width="110px"
          >
            <el-input
              v-model="formData.pouringAbandon"
              placeholder="请输入浇注废型"
              clearable
            />
          </el-form-item>
        </el-col>
        <!--<el-col :span="6">
          <el-form-item label="实际重量" prop="actualWeight" label-width="110px">
            <el-input
              v-model="formData.actualWeight"
              placeholder="请输入实际重量"
              clearable
            />
          </el-form-item>
        </el-col>-->
        <el-col :span="6">
          <el-form-item
            label="实际件数"
            prop="actualQuantity"
            label-width="110px"
          >
            <el-input
              v-model="formData.actualQuantity"
              placeholder="请输入实际件数"
              clearable
            />
          </el-form-item>
        </el-col>
        <!--<el-col :span="6">
          <el-form-item
            label="实际铁水重量"
            prop="actualWaterWeight"
            label-width="110px"
          >
            <el-input
              v-model="formData.actualWaterWeight"
              placeholder="请输入实际铁水重量"
              clearable
            />
          </el-form-item>
        </el-col>-->
        <el-col :span="6">
          <el-form-item
            label="实际包待"
            prop="actualPackage"
            label-width="110px"
          >
            <el-input
              v-model="formData.actualPackage"
              placeholder="请输入实际包待（分钟）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="实际炉待"
            prop="actualStove"
            label-width="110px"
          >
            <el-input
              v-model="formData.actualStove"
              placeholder="请输入实际炉待（分钟）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="炉号" prop="stoveNum" label-width="110px">
            <el-input
              v-model="formData.stoveNum"
              placeholder="请输入炉号"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="模板框号" prop="templateNum" label-width="110px">
            <el-input
              v-model="formData.templateNum"
              placeholder="请输入模板框号"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="冒口批号" prop="castingHeadBatch" label-width="110px">
            <el-input
              v-model="formData.castingHeadBatch"
              placeholder="请输入冒口批号"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="冒口数量" prop="castingHeadQuantity" label-width="110px">
            <el-input
              v-model="formData.castingHeadQuantity"
              placeholder="请输入冒口数量"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="压力（上）" prop="pressureOn" label-width="110px">
            <el-input
              v-model="formData.pressureOn"
              placeholder="请输入压力（上）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="压力（下）"
            prop="pressureDown"
            label-width="110px"
          >
            <el-input
              v-model="formData.pressureDown"
              placeholder="请输入压力（下）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="加砂量（上）"
            prop="sandQuantityUp"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandQuantityUp"
              placeholder="请输入加砂量（上）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="加砂量（下）"
            prop="sandQuantityDown"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandQuantityDown"
              placeholder="请输入加砂量（下）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="砂模硬度1"
            prop="sandMould1Up"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandMould1Up"
              placeholder="请输入砂模硬度1（上）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="砂模硬度1"
            prop="sandMould1Down"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandMould1Down"
              placeholder="请输入砂模硬度1（下）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="砂模硬度2"
            prop="sandMould2Up"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandMould2Up"
              placeholder="请输入砂模硬度2（上）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="砂模硬度2"
            prop="sandMould2Down"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandMould2Down"
              placeholder="请输入砂模硬度2（下）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="砂模硬度3"
            prop="sandMould3Up"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandMould3Up"
              placeholder="请输入砂模硬度3（上）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="砂模硬度3"
            prop="sandMould3Down"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandMould3Down"
              placeholder="请输入砂模硬度3（下）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="砂模硬度4"
            prop="sandMould4Up"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandMould4Up"
              placeholder="请输入砂模硬度4（上）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="砂模硬度4"
            prop="sandMould4Down"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandMould4Down"
              placeholder="请输入砂模硬度4（下）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="砂模硬度5"
            prop="sandMould5Up"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandMould5Up"
              placeholder="请输入砂模硬度5（上）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="砂模硬度5"
            prop="sandMould5Down"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandMould5Down"
              placeholder="请输入砂模硬度5（下）"
              clearable
            />
          </el-form-item>
        </el-col>
        <!--<el-col :span="6">
          <el-form-item
            label="砂模硬度6"
            prop="sandMould6Up"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandMould6Up"
              placeholder="请输入砂模硬度6（上）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="砂模硬度6"
            prop="sandMould6Down"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandMould6Down"
              placeholder="请输入砂模硬度6（下）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="砂模硬度7"
            prop="sandMould7Up"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandMould7Up"
              placeholder="请输入砂模硬度7（上）"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="砂模硬度7"
            prop="sandMould7Down"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandMould7Down"
              placeholder="请输入砂模硬度7（下）"
              clearable
            />
          </el-form-item>
        </el-col>-->
        <el-col :span="6">
          <el-form-item
            label="下芯人员"
            prop="coreSettingUserName"
            label-width="110px"
          >
            <el-input
              v-model="formData.coreSettingUserName"
              placeholder="请输入下芯人员"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="砂芯批号"
            prop="sandCoreBatch"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandCoreBatch"
              placeholder="请输入砂芯批号"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="砂芯数量"
            prop="sandCoreQuantity"
            label-width="110px"
          >
            <el-input
              v-model="formData.sandCoreQuantity"
              placeholder="请输入砂芯数量"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="过滤片数量"
            prop="filterQuantity"
            label-width="110px"
          >
            <el-input
              v-model="formData.filterQuantity"
              placeholder="请输入过滤片数量"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="过滤片批号"
            prop="filterBatch"
            label-width="110px"
          >
            <el-input
              v-model="formData.filterBatch"
              placeholder="请输入过滤片批号"
              clearable
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <template #footer>
      <div class="dialog-footer">
        <el-button
          v-if="!props.isReadonly"
          type="primary"
          :loading="loading"
          @click="handleSubmit"
          >确 定</el-button
        >
        <el-button @click="closeDialog">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import request from "@/utils/request";
import { useDictStoreHook } from "@/store/modules/dictionary"; // 引入
const dictionaryStore = useDictStoreHook();

defineOptions({
  name: "MESMESMODELPLANREPORTADDORUPDATE",
  inheritAttrs: false,
});

const emit = defineEmits(["reset-table", "change-visible"]);

const props = defineProps({
  visible: {
    type: Boolean,
    default: () => {
      return false;
    },
  },
  title: {
    type: String,
    default: () => {
      return "";
    },
  },
  data: {
    type: Object,
    default: () => {
      return {};
    },
  },
  id: {
    type: String,
    default: () => {
      return "";
    },
  },
  isReadonly: {
    type: Boolean,
    default: () => {
      return false;
    },
  },
});

const visibleDialog = ref(false);
watch(
  () => props.visible,
  (newVal: boolean) => {
    visibleDialog.value = newVal;
    setTimeout(() => {
      formRef.value.clearValidate();
    }, 50);
  }
);

const rules = reactive({
  sandDisposeSupply: [
    { required: true, message: "请输入砂处理供砂量", trigger: "blur" },
    { pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" },
  ],
  mouldingSandUsageAmount: [
    { required: true, message: "请输入型砂使用量", trigger: "blur" },
    { pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" },
  ],
  pouringMouldQuantity: [{ required: true, message: "请输入浇注模数", trigger: "blur" },
    { pattern: /^[+-]?\d+?(e[+-]?\d+)?$/, message: "请输入数字" },
  ],
  actualModelMouldQuantity: [{ required: true, message: "请输入实际造型模数", trigger: "blur" },{ pattern: /^[+-]?\d+?(e[+-]?\d+)?$/, message: "请输入数字" }],
  actualPouringMouldQuantity: [{ required: true, message: "请输入实际浇注模数", trigger: "blur" },{ pattern: /^[+-]?\d+?(e[+-]?\d+)?$/, message: "请输入数字" }],
  modelAbandon: [{ required: true, message: "请输入造型废型", trigger: "blur" },{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  pouringAbandon: [{ required: true, message: "请输入浇注废型", trigger: "blur" },{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  actualWeight: [{ required: true, message: "请输入实际重量", trigger: "blur" },{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  actualQuantity: [{ required: true, message: "请输入实际件数", trigger: "blur" },{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  actualWaterWeight: [{ required: true, message: "请输入实际铁水重量", trigger: "blur" },{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  actualPackage: [{ required: true, message: "请输入实际包待（分钟）", trigger: "blur" },{ pattern: /^[+-]?\d+?(e[+-]?\d+)?$/, message: "请输入数字" }],
  actualStove: [{ required: true, message: "请输入实际炉待（分钟）", trigger: "blur" },{ pattern: /^[+-]?\d+?(e[+-]?\d+)?$/, message: "请输入数字" }],
  stoveNum: [
    { required: true, message: "请输入炉号", trigger: "blur" },
    { min: 1, max: 50, message: "长度在 1 到 50 个字符", trigger: "blur" },
  ],
  templateNum: [
    { min: 1, max: 50, message: "长度在 1 到 50 个字符", trigger: "blur" },
  ],
  castingHeadBatch: [
    { min: 1, max: 50, message: "长度在 1 到 50 个字符", trigger: "blur" },
  ],
  castingHeadQuantity: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  pressureOn: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  pressureDown: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  sandQuantityUp: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  sandQuantityDown: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  sandMould1Up: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  sandMould1Down: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  sandMould2Up: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  sandMould2Down: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  sandMould3Up: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  sandMould3Down: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  sandMould4Up: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  sandMould4Down: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  sandMould5Up: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  sandMould5Down: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  sandMould6Up: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  sandMould6Down: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  sandMould7Up: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  sandMould7Down: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  coreSettingUserName: [
    { min: 1, max: 50, message: "长度在 1 到 50 个字符", trigger: "blur" },
  ],
  sandCoreBatch: [
    { min: 1, max: 50, message: "长度在 1 到 50 个字符", trigger: "blur" },
  ],
  sandCoreQuantity: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  filterQuantity: [{ pattern: /^\d{1,18}(\.\d{0,6})?$/, message: "请输入数字" }],
  filterBatch: [
    { min: 1, max: 50, message: "长度在 1 到 50 个字符", trigger: "blur" },
  ],
});

const formRef = ref(ElForm);

let formData = reactive({
  id: "",
  planId: "",
  sandDisposeSupply: "",
  mouldingSandUsageAmount: "",
  pouringMouldQuantity: "",
  actualModelMouldQuantity: "",
  actualPouringMouldQuantity: "",
  modelAbandon: "",
  pouringAbandon: "",
  actualWeight: "",
  actualQuantity: "",
  actualWaterWeight: "",
  actualPackage: "",
  actualStove: "",
  stoveNum: "",
  templateNum: "",
  pressureOn: "",
  pressureDown: "",
  sandQuantityUp: "",
  sandQuantityDown: "",
  sandMould1Up: "",
  sandMould1Down: "",
  sandMould2Up: "",
  sandMould2Down: "",
  sandMould3Up: "",
  sandMould3Down: "",
  sandMould4Up: "",
  sandMould4Down: "",
  sandMould5Up: "",
  sandMould5Down: "",
  sandMould6Up: "",
  sandMould6Down: "",
  sandMould7Up: "",
  sandMould7Down: "",
  coreSettingUserName: "",
  sandCoreBatch: "",
  sandCoreQuantity: "",
  filterQuantity: "",
  filterBatch: "",
  castingHeadBatch: "",
  castingHeadQuantity: "",
  version: "",
  remarks: "",
  createTime: "",
  createdUserId: "",
  createdUserName: "",
  lastUpdateTime: "",
  lastUpdatedUserId: "",
  lastUpdatedUserName: "",
  enabled: "",
  deleted: "",
});

watch(
  () => props.data,
  (newVal: any) => {
    formData.id = "";
    if (newVal?.id) {
      const {
        id,
        planId,
        sandDisposeSupply,
        mouldingSandUsageAmount,
        pouringMouldQuantity,
        actualModelMouldQuantity,
        actualPouringMouldQuantity,
        modelAbandon,
        pouringAbandon,
        actualWeight,
        actualQuantity,
        actualWaterWeight,
        actualPackage,
        actualStove,
        stoveNum,
        templateNum,
        pressureOn,
        pressureDown,
        sandQuantityUp,
        sandQuantityDown,
        sandMould1Up,
        sandMould1Down,
        sandMould2Up,
        sandMould2Down,
        sandMould3Up,
        sandMould3Down,
        sandMould4Up,
        sandMould4Down,
        sandMould5Up,
        sandMould5Down,
        sandMould6Up,
        sandMould6Down,
        sandMould7Up,
        sandMould7Down,
        coreSettingUserName,
        sandCoreBatch,
        sandCoreQuantity,
        filterQuantity,
        filterBatch,
        castingHeadBatch,
        castingHeadQuantity,
        version,
        remarks,
        createTime,
        createdUserId,
        createdUserName,
        lastUpdateTime,
        lastUpdatedUserId,
        lastUpdatedUserName,
        enabled,
        deleted,
      } = newVal;
      Object.assign(formData, {
        id,
        planId,
        sandDisposeSupply,
        mouldingSandUsageAmount,
        pouringMouldQuantity,
        actualModelMouldQuantity,
        actualPouringMouldQuantity,
        modelAbandon,
        pouringAbandon,
        actualWeight,
        actualQuantity,
        actualWaterWeight,
        actualPackage,
        actualStove,
        stoveNum,
        templateNum,
        pressureOn,
        pressureDown,
        sandQuantityUp,
        sandQuantityDown,
        sandMould1Up,
        sandMould1Down,
        sandMould2Up,
        sandMould2Down,
        sandMould3Up,
        sandMould3Down,
        sandMould4Up,
        sandMould4Down,
        sandMould5Up,
        sandMould5Down,
        sandMould6Up,
        sandMould6Down,
        sandMould7Up,
        sandMould7Down,
        coreSettingUserName,
        sandCoreBatch,
        sandCoreQuantity,
        filterQuantity,
        filterBatch,
        castingHeadBatch,
        castingHeadQuantity,
        version,
        remarks,
        createTime,
        createdUserId,
        createdUserName,
        lastUpdateTime,
        lastUpdatedUserId,
        lastUpdatedUserName,
        enabled,
        deleted,
      });
    }
  }
);

/** 关闭表单弹窗 */
function closeDialog() {
  visibleDialog.value = false;
  emit("change-visible", false);
  resetForm();
}

/** 重置表单 */
function resetForm() {
  formRef.value.resetFields();
  formRef.value.clearValidate();
  formData.id = "";
  formData.planId = "";
  formData.sandDisposeSupply = "";
  formData.mouldingSandUsageAmount = "";
  formData.pouringMouldQuantity = "";
  formData.actualModelMouldQuantity = "";
  formData.actualPouringMouldQuantity = "";
  formData.modelAbandon = "";
  formData.pouringAbandon = "";
  formData.actualWeight = "";
  formData.actualQuantity = "";
  formData.actualWaterWeight = "";
  formData.actualPackage = "";
  formData.actualStove = "";
  formData.stoveNum = "";
  formData.templateNum = "";
  formData.pressureOn = "";
  formData.pressureDown = "";
  formData.sandQuantityUp = "";
  formData.sandQuantityDown = "";
  formData.sandMould1Up = "";
  formData.sandMould1Down = "";
  formData.sandMould2Up = "";
  formData.sandMould2Down = "";
  formData.sandMould3Up = "";
  formData.sandMould3Down = "";
  formData.sandMould4Up = "";
  formData.sandMould4Down = "";
  formData.sandMould5Up = "";
  formData.sandMould5Down = "";
  formData.sandMould6Up = "";
  formData.sandMould6Down = "";
  formData.sandMould7Up = "";
  formData.sandMould7Down = "";
  formData.coreSettingUserName = "";
  formData.sandCoreBatch = "";
  formData.sandCoreQuantity = "";
  formData.filterQuantity = "";
  formData.filterBatch = "";
  formData.castingHeadBatch = "";
  formData.castingHeadQuantity = "";
  formData.version = "";
  formData.remarks = "";
  formData.createTime = "";
  formData.createdUserId = "";
  formData.createdUserName = "";
  formData.lastUpdateTime = "";
  formData.lastUpdatedUserId = "";
  formData.lastUpdatedUserName = "";
  formData.enabled = "";
  formData.deleted = "";
}

const loading = ref(false);

/** 造型计划填报保存提交 */
function handleSubmit() {
  formRef.value.validate(async (valid: any) => {
    if (valid) {
      loading.value = true;
      const text = formData.id ? "编辑" : "新增";
      if (!formData.id) {
        formData.planId = props.id;
      }
      await request({
        url: "/mes/mesmodelplanreport/save",
        method: "post",
        data: formData,
      }).finally(() => {
        loading.value = false;
      });
      ElMessage.success(text + `成功`);
      closeDialog();
      emit("reset-table", formData.id);
    }
  });
}

// 组件销毁时调用
onBeforeUnmount(() => {
  visibleDialog.value = false;
  emit("change-visible", false);
});
</script>
